// 封装文章相关请求
import request from '@/utils/request.js'

/**
 * 获取频道的文章列表
 * @param {Object} params {channel_id, timestamp, with_top}
 * @returns promise
 */
export const getArticlesList = params => {
  return request({
    method: 'GET',
    url: '/v1_1/articles',
    params
  })
}

/**
 * 获取文章详情
 * @param {Number} id 文章id
 * @returns promise
 */
export const getArticlesInfo = id => {
  return request({
    method: 'GET',
    url: `/v1_0/articles/${id}`
  })
}

/**
 * 收藏文章
 * @param {*} id 文章id
 * @returns promise
 */
export const addArticleCollected = id => {
  return request({
    method: 'POST',
    url: '/v1_0/article/collections',
    data: {
      target: id
    }
  })
}

/**
 * 取消文章收藏
 * @param {*} id 文章id
 * @returns promise
 */
export const deleteArticleCollected = id => {
  return request({
    method: 'DELETE',
    url: '/v1_0/article/collections/' + id
  })
}

/**
 * 文章点赞
 * @param {*} id
 * @returns
 */
export const addArticleLiking = id => {
  return request({
    method: 'POST',
    url: '/v1_0/article/likings',
    data: {
      target: id
    }
  })
}

/**
 * 取消文章点赞
 * @param {*} id
 * @returns
 */
export const deleteArticleLiking = id => {
  return request({
    method: 'DELETE',
    url: '/v1_0/article/likings/' + id
  })
}
